/**
 * 公司下拉组件
 * 公共组件
 */
import Selection from '../../el/ItemComponent/Selection';
import React from 'react';
import request from '@/utils/request';
interface TransferProps {
  value: string;
  label: string;
}
interface Props {
  value?: any;
  onChange?: Function;
  transfer?: null;
  [props: string]: any;
}
const defaultTransfer: TransferProps = {
  value: 'id',
  label: 'name'
};
// 在此处组装所有的数据
class OuSelection extends React.Component<Props> {
  // props默认值
  static defaultProps = {
    disabled: false,
    multiple: false,
    allowClear: true,
    transfer: defaultTransfer,
    selectRecord: false
  };
  constructor(props) {
    super(props);
  }

  /**
   * 请求数据方法
   * @returns
   */
  onRequest = async () => {
    const res = await request(`/yst-support/org/component/ou/list`, {
      method: 'get'
    });
    if (res.success) {
      res.data =
        res.data &&
        res.data.map((item) => ({
          ...item,
          code: item.ouCode,
          name: item.ouName
        }));
      return res;
    }
    return res;
  };
  render() {
    return (
      <Selection
        {...this.props}
        onChange={this.props.onChange}
        request={this.onRequest}
      />
    );
  }
}
export default OuSelection;
